package com.scaffold.card.service;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wangjg.commons.page.Page;

import com.scaffold.card.dao.CategoryDAO;
import com.scaffold.card.dao.SimpleCardDAO;
import com.scaffold.card.entity.SimpleCard;

@Service
@Transactional
public class SimpleCardService {

	@Autowired
	private SimpleCardDAO simpleCardDAO;
	@Autowired
	private CategoryDAO categoryDAO;

	public SimpleCard getSimpleCard(Long id ) {
		return this.simpleCardDAO.findById(id);
	}

	public void save(SimpleCard simpleCard){
		Timestamp now = new Timestamp(System.currentTimeMillis());
		if(simpleCard.getId()==null){
			simpleCard.setCreated(now);
			simpleCard.setModified(now);
			this.simpleCardDAO.save(simpleCard);
		}else{
			simpleCard.setModified(now);
			this.simpleCardDAO.update(simpleCard);
		}
	}

	public void update(SimpleCard simpleCard){
		Timestamp now = new Timestamp(System.currentTimeMillis());
		simpleCard.setModified(now);
		this.simpleCardDAO.update(simpleCard);
	}

	public void delete(SimpleCard simpleCard){
		this.simpleCardDAO.delete(simpleCard);
	}
	
	public List<SimpleCard> findByCategoryId(Long categoryId) {
		return this.simpleCardDAO.findByCategoryId(categoryId);
	}

	public List<SimpleCard> pageQuery(Page page, Long categoryId, String keyword) {
		return this.simpleCardDAO.pageQuery(page, categoryId, keyword);
	}

	public List<SimpleCard> queryValidList(Long categoryId) {
		return this.simpleCardDAO.queryValidList(categoryId);
	}
	
	public List<Long> getCardIdList(Long categoryId){
		return this.simpleCardDAO.getCardIdList(categoryId);
	}

}
